import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router, NavigationEnd } from '@angular/router';
import { map, tap, filter, find, startWith } from 'rxjs/operators';
import { Route } from '@angular/compiler/src/core';
import { BehaviorSubject, Subject } from 'rxjs';

@Component({
	selector: 'm-message',
	templateUrl: './message.component.html',
	styleUrls: ['./message.component.scss'],
})
export class MessageComponent implements OnInit {
	url = new Subject();

	navs = [
		{
			label: '站内信',
			link: '/message/web',
		},
		{
			label: '平台消息',
			link: '/message/client',
		},
		// {
		//     label: '消息模版',
		//     link: '/message/template',
		// },
	];
	findFirstChild = (route: ActivatedRoute) => (!route.firstChild ? route : this.findFirstChild(route.firstChild));
	hideNav$ = this.router.events.pipe(
		filter(event => event instanceof NavigationEnd), // 全局路由变动
		startWith(null),
		map(() => this.findFirstChild(this.route)), // 遍历最上层路由
		map(route => route.snapshot.data['hide_nav']), // 取出路由数据
	);
	constructor(private route: ActivatedRoute, private router: Router) {}

	ngOnInit() {}
}
